home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Commodore Free 22
/
Commodore_Free_Issue_22_2008_Commodore_Computer_Club.d64
/
t.b guide 7.1
< prev
next >
Wrap
Text File
|
2023-02-26
|
11KB
|
376 lines
u
In the Beginning CHAPTER 7 SECTION 1
\Lord Ronin from Q-Link\
Welcome to the second side of a 1541
disk. Well, at least on the original
creation. <G>
FOR NEXT LOOPS
--------------
FOR NEXT LOOPS are what the Commodore
user book has for the next piece of
information. By this time I suspect
that you have some idea that what the
manual presents is not a full
programming course, Only a taster of
the subject. Yet the manual is an
attempt to make the computer a
friendly, rather than a scary thing.
Each of these parts really deserve
full chapters in programming manuals.
Getting that information out of the
way. Here is what the Commodore user
book has for you to type in,
new <press return, clears the memory>
10 FORCT=1TO5
20 ?"COMMODORE 64"
30 NEXTCT
Like a nagging yiddish momma, remember
to press return after typing in a
line. Forgetting to press Return is a
common fault that we all share, and
all forget to do from time to time.
Forgetting to press return is on
annoying user error to find that the
line didn't take, when you are
debugging 6 pages of a type in
programme.
Yeah when you run this programme, it
does the same thing as the IF THEN
Just that it is smaller. Lets go over
it a bit. Line 10, right they are
called line numbers. Although I have a
programming book collection that isn't
American English that calls them line
labels. Right back on topic, Line 10
says the same thing that three lines
in the IF THEN programme we did
recently. Says that "C" is going to
be from 1 to 5. Line 20 says that the
C= is to print that word line. Line 30
says to do the next ct. Looping from
line 10 back through for the 5 prints
A bit of a pause here, I dig that this
is all strange and new and to be
polite <a rarity for me> odd for you,
these commands and typing in the
stuff. Alien as you see it for the
first time. Personally I was scared to
type any of this into the computer,
yet this is the stuff from that manual
that came in the box with the C=64 PC.
Pretty much everyone that uses, used,
and programmes; then as well as now,
started with to learn how to use the
machine. Thankfully this isn't a
series on how to programme, I am not
that good. Despite my vanity and ego.
Here, when you type in and run the
programmes, You are doing the same as
a guy 25+ years ago did. Feeling the
same things as he felt, across the
years. Out of the philosophic musings
and lets get back to the programming
stuff.
What the manual doesn't say is that a
FOR NEXT loop could be used for a
timer in a programme. 100 for fz = 1
to 250 : next fz. If I wrote that
correctly from memory. This will delay
the programme for a short amount of
time, then the next line of the
programme will happen. Mainly I have
used this as a delay in my little
intro screens. I mean that I have a
bit of text on the screen, done with
that print statement, this will sit
there for a time and then another
thing will pop up, Like an entire new
screen. That may sound like a big
thing, Only because you haven't done
it yet, and I write it vague enough to
make it sound great, When in reality
it is just a few steps past what is in
this manual.
Here is the next thing they have for a
FOR NEXT.
NEW <RETURN>
10 FORNB=1TO10 STEP.5
20 ?NB,
30 NEXTNB
Tearing this apart. Before or after
you have rU (run) it. Did the new
part. Then declare on line 10 the
variable will be "nb". I think that
they did that to suggest Number.
Saying that it is going to be starting
at 1 and ending at 10. That is sort of
familiar to you from the previous
stuff. But what the smeg is "step .5"
Step is just what it says, a step,
sort of like a step in walking, or a
step in a set of stairs, One thing at
a time. You don't need to tell the
C=64 PC to go forward in the steps, If
it is just one full step. If you want
to run the programme above without the
.5 part, Then it will act as if you
had said "step 1". Gonna come back to
that in a bit.
Next line tells it to print the nb
variable, Last line tells it to go to
the next nb variable. As you can see
from the last few examples of
variables, the value of the variable,
or less techy said, what is in the
variable, is changing each time
through the programme. Note in the
above one there is that comma.
Explaining why there are 4 columns of
printout on the screen. All this
little thing does is count from 1 to
10, pretty much seen in that first
line. Difference is that it is doing
it in that .5. OK if you haven't run
the programme, it starts off as 1 1.5
2 2.5 and so on until it reaches 10.
Step .5 is the way its was told to
count, Like I said above. If you
remove that "step .5" it will count by
ones. In fact if you want it to count
by ones in a forward direction, you
don't even need to put in the step
section. If you are in an experimental
mood, Then try changing the "step .5"
to "step -1". Try it as a "step 2" or
a "step 5", See how it works. Well the
step -1 won't work, you should see
something like ?syntax error line 10.
Why? Kind of hard to count from a low
positive number like 1, Up to a high
positive number like 10, When you are
counting in negative numbers <VBG>.
Just change it from 1 to 10, over to
10 to 1 to make it work in line 10.
ADVANCED BASIC
--------------
Well we have made it to page 41,
titled Advanced Basic. Compared to
other books that I have seen. The
commands may be advanced, but the
lessons are not.
First thing to type in is this little
animation programme, right there will
be some sort of simple animation on
the screen. Because the writing
programme that I am using doesn't have
the full character set. I am altering
this programme a bit. Type it in and
give it a run, I'll explain some
things about it afterwards.
NEW <clears remember?>
10 rem bouncing ball
20 ?"<clear/home>" <they want you to
type the line number, the print
command, the first quote, then a
shifted clear home key, followed by
ending the quote.>
25 FOR X=1TO10:?"<DO ONE CURSOR
DOWN>":NEXT
30 FORBL=1TO40
40 ?" *<DO A CURSOR LEFT>";:
50 FOR TM=1TO5
60 NEXT TM
70 NEXT BL
75 REM MOVES BALL RIGHT TO LEFT
80 FOR BL = 40TO1 STEP -1
90 ?" <CURSOR LEFT><CURSOR LEFT> *
<CURSOR LEFT>";
100 FOR TM=1TO5
110 NEXT TM
120 NEXT BL
130 GOTO20
Scary isnt it? Yet there are some
things here that we have already
covered in the previous parts. If I
typed this correctly, and you entered
it correctly, there should be a *
symbol that is about 20 lines down on
the screen and goes from left to
right, then right to left. Actual
programme uses the shifted Q to get
that filled in circle or ball graphic.
We are going to tear this apart,
Because there are some points to be
made which may have thrown off your
typing it in.
Line 10 starts off with the term REM,
this is short for REMark. When the 64
PC sees that in a programme, it is
lazy and doesn't want to read remarks,
so it acts as if it isn't there at
all. This is a way for a programmer to
insert information in the programme
for others to see and work upon. I
have seen it in menu programmes, A way
to tell the user the how and what.
Also seen it in BBS games, breaking
the parts of the programme down for
editing or fixing, Thats the good
part. The bad part is that it also
eats up memory space.
Line 20 I had to add explanation. You
already have the print statement; know
about the fact that what is in quotes
is what you are going to have printed
to the screen. Notice that when you
did the quote and then the shifted
clear/home keys there was a symbol
that appeared. That is the symbol for
that shifted clear home, Generally it
is called just clear home; When not
shifted it is called clear.
Line 25 is wrong. Yuppers it is wrong
in the book, in all 27 copies of the
book that I have, This is written
incorrectly! Shocked that I contradict
the writers of the book? Well there is
another line coming up that I will say
is wrong as well. Look at the line, it
says that X=1to10. So you know that
there is a 10 something in this line
for the programme. Shows you the ":"
symbol, in fact the book states, that
indicates a new command. Now you make
a quote and then do just one down
cursor movement ending the quote. That
will be another strange symbol to you.
A : follows and the next command.
Well if you haven't run it yet. Give
it a try, Ill be here to explain....
OK see that it goes not 10 lines down,
It goes 20 lines down, What the smeg?
Many of the members of my users group
have thought that they did it wrong
and couldn't fix or see the problem,
well here is a problem. Says to do 1
to 10. Using a for next loop on that
line, What you don't see is the fact
that : with a next as a command, adds
another line as if you had said 1 to
20. There is a typo on this line. In
order to fix it you need to type
?"<cursor down>";:next. The use of
that ; will keep it on the same line
of command. Basically it won't go down
20 lines just the 10 it is supposed to
do for this programme.
Line 30 is another FOR NEXT loop, but
only the FOR is on the line, BL is for
the ball character. Says it is to be
1to40. This line is not wrong, run the
programme, and take a hard look at the
left and right side of the screen.
Keep a careful eye out and you will
see for a short moment, the graphic
you used go up one line on one side
and down one line on the other, Just
one character. But it is going over
the line on the screen, this is
because of this line #80. OK scratch
your head and wonder why, The
programme is written so that you will
the use it first. There are 40 columns
on the screen, why is it doing 41 in
each direction? The truth is that it
isn't really it is doing 40 columns.
Just that in my opinion, the author
didn't want to go into a hard to
understand the part about counting, in
1982ce.
I mentioned this a little bit earlier,
there are 40 columns; But remember
that in computer things we will start
the count at 0, not at 1. The 64 is
doing what it was told, so no problem
there. Well it means that you typed
the programme in correctly from the
book. Only that it was written to sort
of re-enforce the 40 column part of
the screen, i take it as a something
that was glossed over for the time it
was written. OK to correct this, we
just need to change that 40 to 39 in
the line. Can tell you that this shows
two things about programming, one is
start on some, but not all things, at
0. The other is well ah, just don't
believe everything that is in a book
or magazine to always be 100% correct,
You may have to tweak with it a bit.
Line 40 may have caused you trouble in
the way I wrote it, we have the print
command, then the quote. Yes there is
really a space before the * symbol,
that needs to be in your line,
Followed by one cursor left command.
Line 50 sets another FOR loop, here it
is TM and it is 1 to 5. Think of this
as Time and you will see it is the
delay, as done in line 60, where it
does the NEXT part, looping between
those two lines 5 times before it goes
to line 70. Line 70 will print on the
screen the next variable called BL, Or
the graphic symbol that you used.
Line 75 is just another REMark,
Indicating a new part of the
programme, The area where the motion
of the ball is reversed. Line 80 is
the same as line 30 In that it is
using the same variable label. Also
that it is doing a FOR and it is doing
that 40 column movement, change that
40 to 39 to keep it on one line. Note
that it starts at 40 and goes to 1,
using that step thing at a -1 that
moves the gfx from the right to the
left.
Continued in Section 2